
package com.zhx.service;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhx.dao.TbRuralCMSOfficeMapper;
import com.zhx.entity.TbRuralCMSOffice;

@Service
@Transactional
public class RuralCMSOfficeService {
	@Autowired
	private TbRuralCMSOfficeMapper ruralCMSOfficeMapper;

	/**
	 * 添加农合机构信息
	 * @param tbRuralCMSOffice
	 */
	public void add(TbRuralCMSOffice tbRuralCMSOffice){
		tbRuralCMSOffice.setCreateTime(new Timestamp(System.currentTimeMillis()));
		tbRuralCMSOffice.setUpdateTime(new Timestamp(System.currentTimeMillis()));
		
		ruralCMSOfficeMapper.insertSelective(tbRuralCMSOffice);
	}
	
	/**
	 * 根据主键ID删除一条信息
	 * @param id
	 */
	public void delete(Integer id){
		ruralCMSOfficeMapper.deleteByPrimaryKey(id);
	}
	
	/**
	 * 根据对象信息进行更新
	 * @param tbRuralCMSOffice
	 */
	public void edit(TbRuralCMSOffice tbRuralCMSOffice){
		tbRuralCMSOffice.setUpdateTime(new Timestamp(System.currentTimeMillis()));
		
		ruralCMSOfficeMapper.updateByPrimaryKeySelective(tbRuralCMSOffice);
	}
	
	/**
	 * 查询所有农合机构信息，可以进行模糊查询，需要进行分页
	 * @return 农合机构信息列表
	 */
	public PageInfo<TbRuralCMSOffice> getRuralCMSOfficeList(Integer currentPage, Integer limit, String officeName){
		//利用PageHelper分页查询 注意：这个一定要放查询语句的前一行,否则无法进行分页,因为它对紧随其后第一个sql语句有效
        PageHelper.startPage(currentPage, limit);
        List<TbRuralCMSOffice> list = ruralCMSOfficeMapper.getRuralCMSOfficeList(officeName);
        PageInfo<TbRuralCMSOffice> pageInfo = new PageInfo<TbRuralCMSOffice>(list);
		return pageInfo;
	}
	
	/**
	 * 通过主键查找一条农合机构信息
	 * @param id
	 * @return
	 */
	public TbRuralCMSOffice getRuralCMSOffice(Integer id){
		
		return ruralCMSOfficeMapper.selectByPrimaryKey(id);
	}
	
	
}
